package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.CargoloadBean;
import com.by.bean.PriceBean;
import com.by.common.bean.Page;
import com.by.common.bean.PageBean;
import com.by.common.bean.ResultBean;
import com.by.common.controller.BaseController;
import com.by.query.CargoloadQuery;
import com.by.service.CargoloadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author:
 * @date: 2025/2/17
 * @version: 1.01
 * @since: jdk11
 */
@RestController
@RequestMapping("/api")
@Api(tags = "货物信息管理")
public class CargoloadController extends BaseController {

    @Autowired
    CargoloadService cargoloadService;

    @ApiOperation("查询表单信息")
    @GetMapping("/inquire")
    public ResultBean get(int id){
        CargoloadBean car = cargoloadService.get(id);
        return new ResultBean(200,"表单信息",car);
    }
    @ApiOperation("保存货代表")
    @PostMapping("/cargoloadsave")
    public ResultBean save(@RequestBody CargoloadBean cargoloadBean){
        int rs = cargoloadService.save(cargoloadBean);
        return saveResult(rs);
    }
    @ApiOperation("修改货代表")
    @PutMapping ("/changecar")
    public ResultBean update(CargoloadBean cargoloadBean){
        int rs = cargoloadService.update(cargoloadBean);
        return updateResult(rs);
    }
    @ApiOperation("删除货代表数据")
    @PutMapping("/deletecar")
    public ResultBean delete(Integer id){
        int rs = cargoloadService.delete(id);
        return updateResult(rs);
    }
    @ApiOperation("查询货代表信息集合")
    @PostMapping("/postcar")
    public ResultBean<PageBean<List<CargoloadBean>>> queryByMap(@RequestBody CargoloadQuery query){
        PageBean page = cargoloadService.queryByMap(BeanUtil.beanToMap(query));
        return success("查询成功",page);
    }
}
